//
//  MyViewController.m
//  OwnDefinitionDelegete
//
//  Created by guo xiangyu on 15/5/18.
//  Copyright © 2018年 潇  岩. All rights reserved.
//

#import "MyViewController.h"
#import "TimeModel.h"
//4.实现代理协议
@interface MyViewController ()<TimeModelDelegete>{
    
    UILabel *label;
    UIButton *button;
    
}

@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor=[UIColor grayColor];
    
    label=[[UILabel alloc]initWithFrame:CGRectMake(0, 200, [UIScreen mainScreen].bounds.size.width, 50)];
    label.text=@"春逼";
    label.backgroundColor=[UIColor redColor];
    label.textAlignment=NSTextAlignmentCenter;
    [self.view addSubview:label];
    
    button=[[UIButton alloc]initWithFrame:CGRectMake(50, 350, 300, 50)];
    [button setTitle:@"点击" forState:UIControlStateNormal];
    button.backgroundColor=[UIColor blueColor];
    [button addTarget:self action:@selector(Thing) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//5.实现协议中的方法
-(void)timeModel:(TimeModel *)model withZoneName:(NSString *)name{
//    处理时区名称，得到时间，显示到label上
//    系统提供的一个用于时间格式化的类
//    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
//    [formatter setDateFormat:@"HH:mm:ss  z"];
//    [formatter setTimeZone:[[NSTimeZone alloc]initWithName:name]];
//    NSData *date=[[NSData alloc]init];
//    NSLog(@"呵呵呵%@",date);
//    NSString *result=[formatter stringFromDate:date];
//    NSLog(@"哈哈哈%@",result);
//    创建一定时间间隔的NSDate对象：
    
    NSDate *date = [NSDate date];//获取当前的时间
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    
    [formatter setDateFormat:@"yyyy-MM-dd a HH:mm:ss EEEE"];
    
    NSLog(@"date = %@",[formatter stringFromDate:date]);
    label.text=[NSString stringWithFormat:@"%@ ", [formatter stringFromDate:date]];
//    NSTimeInterval secondsPerDay = 224 * 660 * 60;
//    //明天时间
//    NSDate *tomorrow = [[NSDate alloc] initWithTimeIntervalSinceNow:secondsPerDay];
//    label.text=[NSString stringWithFormat:@"%@ ", tomorrow];
    
    
}

-(void)Thing{
    
    NSLog(@"哈哈哈哈");
    
//    6.让委托对象的引用指向代理对象
    TimeModel *model=[[TimeModel alloc]init];
    model.delegete=self;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
